package com.kaisademo.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kaisademo.zhxy.mapper.GradeMapper;
import com.kaisademo.zhxy.pojo.Grade;
import com.kaisademo.zhxy.service.GradeService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade> implements GradeService {
    @Override
    public IPage<Grade> getGradeByOpr(Page<Grade> gradePage, String gradeName) {
        LambdaQueryWrapper<Grade> gradeLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(!StringUtils.isEmpty(gradeName)){
            //通过gradeName在Grade表中进行模糊查询
            gradeLambdaQueryWrapper.like(Grade::getName,gradeName);
        }
        gradeLambdaQueryWrapper.orderByDesc(Grade::getId);
        Page<Grade> ResultPage = baseMapper.selectPage(gradePage, gradeLambdaQueryWrapper);
        return ResultPage;
    }

    @Override
    public List<Grade> getGrades() {
        List<Grade> gradeList = baseMapper.selectList(null);
        return gradeList;
    }
}
